﻿namespace SugarTank.Mobile.IoC
{
    using CommonTypes.Domain;
    using Managers;
    using Managers.Contracts;
    using Microsoft.Devices;
    using Ninject.Modules;
    using Translators;
    using Translators.Contract;
    using ViewModels;

    public class Module : NinjectModule
    {
        /// <summary>
        /// Loads the module into the kernel.
        /// </summary>
        public override void Load()
        {
            //// Managers
            switch (Environment.DeviceType)
            {
                case DeviceType.Device:
                    LoadDeviceManagers();
                    break;
                default:
                    LoadEmulatedManagers();
                    break;
            }

            //// Translators
            Bind<ITranslator<Item, ItemViewModel>>().To<ItemToItemViewModel>().InSingletonScope();
        }

        /// <summary>
        /// Loads the emulated managers.
        /// </summary>
        private void LoadEmulatedManagers()
        {
            Bind<IContentManager>().To<ContentManager>().InSingletonScope();
            Bind<IMediaManager>().To<MediaManager>().InSingletonScope();
            Bind<IResourceManager>().To<ResourceManager>().InSingletonScope();
            Bind<ILauncherManager>().To<LauncherManager>().InSingletonScope();
            Bind<IChooserManager>().To<ChooserManager>().InSingletonScope();
            Bind<IGeographicManager>().To<EmulatedGeographicManager>().InSingletonScope();
        }

        /// <summary>
        /// Loads the device managers.
        /// </summary>
        private void LoadDeviceManagers()
        {
            Bind<IResourceManager>().To<ResourceManager>().InSingletonScope();
            Bind<IMediaManager>().To<MediaManager>().InSingletonScope();
            Bind<IContentManager>().To<ContentManager>().InSingletonScope();
            Bind<ILauncherManager>().To<LauncherManager>().InSingletonScope();
            Bind<IChooserManager>().To<ChooserManager>().InSingletonScope();
            Bind<IGeographicManager>().To<GeographicManager>().InSingletonScope();
        }
    }
}